
<!DOCTYPE html>
<html lang="en" class="app">
    <head>
        <title>Coupon Management | <?php echo SITENAME; ?></title>
        <meta name="description" content="" />
        <?php fnGetHeader(); ?>
    </head>
    <body>
        <?php fnGetSidebar(); ?>
        <section id="content">
            <section class="vbox">
                <section class="scrollable padder">
                    <div class="m-b-md"> <?php echo @$this->noti; ?>
                        <h3 class="m-b-none"><?php
                            if (GET('action') == 'edit') {
                                echo 'Edit';
                            } else {
                                echo 'Add';
                            }
                            ?> Coupon</h3>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">

<?php if (GET('action') == "add" || GET('action') == "edit") { ?>
                                <section class="panel panel-default">
                                    <header class="panel-heading font-bold">Coupon</header>
                                    <div class="panel-body">
                                        <?php
                                        if (count($this->ErrorMessage) > 0):
                                            foreach ($this->ErrorMessage as $key => $value):
                                                ?>
                                                <div id="msg" class="alert alert-danger" style="opacity: 0.846072;">
                                                    <button data-dismiss="alert" class="close" type="button">×</button>
                                                    <i class="fa fa-ok-sign"></i> <?php echo $value; ?>
                                                </div>
                                            <?php
                                            endforeach;
                                        endif;
                                        ?>  
                                        <form class="bs-example form-horizontal" method="post" enctype="multipart/form-data">
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Name</label>
                                                <div class="col-lg-8">
                                                    <input class="form-control" placeholder="Coupon Code" name="cp_code" id="cp_code" type="text" value="<?php echo $this->cp_code; ?>"  readonly="readonly">
                                                </div>
                                                <?php  if (GET('action') == 'add') {?>
                                                <div class="col-lg-2">
                                                    <button type="button" id="random_code" name="random_code" value="Random Code" class="btn btn-s-md btn-primary ">
                                                            Generate Code
                                                    </button>
                                                </div>
                                                <?php }?>
                                            </div>
                                           
                                            
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">How many times can this discount be used?</label>
                                                <div class="col-lg-6">
                                                    <input class="form-control" placeholder="" name="cp_used_time" id="cp_used_time" <?php if($this->no_limit_used == 1):echo 'readonly';endif; ?> type="text" value="<?php if($this->no_limit_used == 1): echo '';else:echo $this->cp_used_time;endif; ?>">
                                                </div>
                                                <div class="col-lg-4">
                                                    <input type="checkbox" name="no_limit_used" id="no_limit_used" <?php if($this->no_limit_used == 1):echo 'checked';endif;?> value="1"/> 
                                                    <label for="no_limit_used">No Limit</label>
                                                </div>
                                             </div>
                                            
                                            
                                            
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Discount Type</label>
                                                <div class="col-lg-10">
                                                    <select class="form-control" name="cp_type" id="cp_type"/>
                                                        <option value="all_order" <?php if($this->cp_type == 'all_order'):echo 'selected';endif;?>>All Order</option>
                                                        <option value="orders_over" <?php if($this->cp_type == 'orders_over'):echo 'selected';endif;?>>Orders Over</option>
                                                        <option value="collection" <?php if($this->cp_type == 'collection'):echo 'selected';endif;?>>Collection</option>
                                                        <option value="specific_product" <?php if($this->cp_type == 'specific_product'):echo 'selected';endif;?>>Specific Product</option>
                                                    </select>
                                                </div>
                                             </div>
                                            
                                            <div class="form-group" id="category_div" <?php if($this->cp_type != 'collection'):?> style="display: none" <?php endif;?>>
                                                <label class="col-lg-2 control-label">Category</label>
                                                <div class="col-lg-10">
                                                    <select class="form-control" name="cp_cat_id" id="cp_cat_id"/>
                                                        <option value="">Select Category</option>
                                                        <?php foreach($this->categoryData as $ckey =>$cvalue):?>
                                                        <option <?php if($this->cp_cat_id == $cvalue['cat_id']):echo 'selected';endif;?> value="<?php echo $cvalue['cat_id'] ?>"><?php echo $cvalue['cat_name'] ?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                </div>
                                             </div>
                                            
                                            <div class="form-group" id="product_div" <?php if($this->cp_type != 'specific_product'):?> style="display: none" <?php endif;?>>
                                                <label class="col-lg-2 control-label">Product</label>
                                                <div class="col-lg-10">
                                                    <select class="form-control" name="cp_prd_id" id="cp_prd_id"/>
                                                        <option value="">Select Product</option>
                                                        <?php foreach($this->productData as $pkey =>$pvalue):?>
                                                        <option <?php if($this->cp_prd_id == $pvalue['prd_id']):echo 'selected';endif;?> value="<?php echo $pvalue['prd_id'] ?>"><?php echo $pvalue['prd_name'] ?></option>
                                                        <?php endforeach;?>
                                                    </select>
                                                </div>
                                             </div>
                                            
                                            <div class="form-group" id="order_price_div" <?php if($this->cp_type != 'orders_over'):?> style="display: none" <?php endif;?> >
                                                <label class="col-lg-2 control-label">Order Price</label>
                                                <div class="col-lg-10">
                                                    <input class="form-control" placeholder="Order Price" name="cp_order_price" id="cp_order_price" type="text" value="<?php echo $this->cp_order_price; ?>">
                                                </div>
                                            </div>
                                            
                                            
                                            <div class="form-group" id="apply_discount_div" <?php 
											
											if($this->cp_type == 'all_order' || $this->cp_type == 'orders_over' || GET('editUid')==''):?> style="display: none" <?php endif;?>>
                                                <label class="col-lg-2 control-label">Apply Discount</label>
                                                <div class="col-lg-10">
                                                    <select class="form-control" name="cp_apply_discount" id="cp_apply_discount"/>
                                                        <option value="only_order" <?php if($this->cp_apply_discount == 'only_order'):echo 'selected';endif;?>>Only once in order</option>
                                                        <option value="per_item" <?php if($this->cp_apply_discount == 'per_item'):echo 'selected';endif;?>>To every applicable item in the cart</option>
                                                    </select>
                                                </div>
                                             </div>
                                            
                                            
                                            
                                            
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Price</label>
                                                <div class="col-lg-10">
                                                    <input class="form-control" placeholder="Price" name="cp_price" id="cp_price" type="text" value="<?php echo $this->cp_price; ?>">
                                                </div>
                                            </div>
                                            
                                            
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Start Date</label>
                                                <div class="col-lg-3">
                                                    <input class="form-control datepicker" placeholder="Start Date" name="cp_startdate" id="cp_startdate" type="text" value="<?php echo $this->cp_startdate; ?>" required />    
                                                </div>
												<input type="hidden" id="hidden_expirystatus" value="<?php echo $this->cp_expirystatus ;?>"/>
                                                <label class="col-lg-2 control-label">Expiry Date</label>
                                                <div class="col-lg-3">
                                                    <input class="form-control datepicker cp_expiry_date" placeholder="Expiry Date" 
                                                        <?php if($this->cp_expirystatus == 1):echo 'readonly';endif; ?> name="cp_expiry_date" 
                                                        <?php if($this->cp_expirystatus == 1): echo 'id="cp_expiry"';else:echo 'id="cp_expiry_date"';endif;?>
                                                     type="text" value="<?php if($this->cp_expirystatus == 1):else: echo $this->cp_expiry_date;endif; ?>" required />    
                                                </div>
                                                <div class="col-lg-2">
                                                    <input type="checkbox" name="cp_expirystatus" id="cp_expirystatus" <?php if($this->cp_expirystatus == 1):echo 'checked';endif; ?> value="1"/> 
                                                    <label for="cp_expirystatus">Never expires</label>
                                                </div>
                                                
                                            </div>
                                           
   <!--                                             
                                            <div class="form-group">
                                                <label class="col-lg-2 control-label">Status</label>
                                                <div class="col-lg-10">
                                                    <select required="" id="cp_status" class="form-control" name="cp_status">
                                                        <option value="">--Select Status--</option>
                                                        <option value="1" <?php if (GET('editUid')) {
                                            if ($this->editrow['cp_status'] == 1) {
                                                ?> selected <?php }
                                                    }
                                                    ?>>Active</option>
                                                        <option value="0" <?php if (GET('editUid')) {
                                                        if ($this->editrow['cp_status'] == 0) {
                                                            ?> selected <?php }
                                                    }
                                                    ?>>Inactive</option>
                                                    </select>
                                                </div>
                                            </div>
-->

                                            <!---- Button -->
                                            <div class="form-group">
                                                <div class="col-lg-offset-2 control-label col-lg-10">
                                                        <?php
                                                        if (GET('editUid')) {
                                                            echo '<input type="hidden" name="editUid" value="' . GET('editUid') . '">';
                                                        }
                                                        ?>
                                                    <button type="submit" name="submit" value="Submit" class="btn btn-s-md btn-primary ">
    <?php
    if (GET('editUid')) {
        echo 'Update';
    } else {
        echo "Create";
    }
    ?>
                                                    </button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </section>
                            </div>
                        </div>

    <?php
} else {
    ?>

                        <section class="panel panel-default">
                            <header class="panel-heading"> All Coupons </header>
                            <div class="row text-sm wrapper">
                                <form action="" method="get">
                                    <div class="col-sm-3">
                                        <div class="input-group">
                                            <input class="input-sm form-control" placeholder="Search" name="q" type="text">
                                            <span class="input-group-btn">
                                                <input type="hidden" name="action" value="view">
                                                <button class="btn btn-sm btn-default" type="submit" name="search" value="search">Go!</button>
                                            </span> </div>
                                    </div>
                                </form>
                            </div>
                            <form action="" method="post">
                                <div class="table-responsive">
                                    <table class="table table-striped b-t b-light text-sm">
                                        <thead>
                                            <tr>
                                                <th width="20"><input type="checkbox"></th>
                                                <th class="th-sortable" data-toggle="class">Coupon Code </th>
                                                <th class="th-sortable" data-toggle="class">Start Date </th>
                                                <th class="th-sortable" data-toggle="class">Expiry Date </th>
                                                <th class="th-sortable" data-toggle="class">Price </th>
                                                <th>Last Modify</th>
                                                <th>Action</th>
                                                <th width="60"></th>
                                            </tr>
                                        </thead>
                                        <tbody>
    <?php ?>
    <?php
    if (count($this->PagingNationFetch) > 0) {
        foreach ($this->PagingNationFetch as $PagingNationFetch) {
            ?>
                                                    <tr>
                                                        <td><input name="cp_id[]" value="<?php echo $PagingNationFetch['cp_id'] ?>" type="checkbox"></td>
                                                        <td><?php echo stripslashes($PagingNationFetch['cp_code']) ?></td>
                                                        <td><?php echo $PagingNationFetch['cp_startdate'] ?></td>
                                                        <td><?php 
                                                        if($PagingNationFetch['cp_expirystatus'] == 1):
                                                        else:   
                                                            echo $PagingNationFetch['cp_expiry_date'];
                                                        endif;
                                                         ?></td>
                                                        <td><?php echo $PagingNationFetch['cp_price'] ?></td>
                                                        <td><?php echo getAdmin($PagingNationFetch['LastModifyBy']); ?></td>
                                                        <td><a href="<?php echo URL ?>coupon/?action=edit&editUid=<?php echo $PagingNationFetch['cp_id'] ?>"><i class="fa fa-edit"></i></a>
                                                        <!--<a href="<?php echo SITEURL ?><?php echo $PagingNationFetch['cat_alias'] ?>" target="_blank"><i class="fa fa-eye"></i></a>
                                                            -->
                                                        </td>
                                                    </tr>
        <?php
        }
    } else {
        ?>
                                                <tr>
                                                    <td colspan="5" style="text-align: center"><b>No Record Found</b></td>
                                                </tr>
    <?php } ?>



                                        </tbody>
                                    </table>
                                </div>
                                <footer class="panel-footer">
                                    <div class="row">
                                        <div class="col-sm-4 hidden-xs">

                                            <button type="submit" name="delete" onClick="return confirm('Are you sure to delete?');" class="btn btn-sm btn-default">Delete</button>
                                        </div>

                                        <div class="col-sm-8 text-right text-center-xs">
    <?php
    echo pagination($this->statement, $this->limit, $this->page, '?', $this->oldData);
    ?>
                                        </div>

                                    </div>
                                </footer>
                            </form>
                        </section>

<?php } ?>
                </section>
            </section>
        </section>
<?php fnGetFooter(); ?>
        <!-- file input --> <script src="<?php echo TEMPLATE; ?>js/file-input/bootstrap-filestyle.min.js" cache="false"></script>
        <script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
        <script src="<?php echo SITEURL . VIEW; ?>js/datepicker/bootstrap-datepicker.js"></script>
        <script src="<?php echo SITEURL . VIEW; ?>js/coupon.js"></script>
        <script>
            function GetKeyword()
            {
                $("#searchTags").val($("#keywords").val());
            }
        </script>
    </body>
</html>

